package com.jackeysun.app_widget

import android.content.Intent
import android.media.AudioManager
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import com.jackeysun.app_widget.databinding.ActivityMainBinding
import com.jackeysun.widget.LoadingDialog


class MainActivity : AppCompatActivity() {

    val loading: LoadingDialog by lazy { LoadingDialog(this) }
    private lateinit var mainBinding: ActivityMainBinding


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        mainBinding = ActivityMainBinding.inflate(layoutInflater)
        setContentView(mainBinding.root)
        mainBinding.btn.setProgress(progress = 80)

//        val proxy: HttpProxyCacheServer = App.httpProxyCacheServer
//        val proxyUrl = proxy.getProxyUrl(DataSource.mp3)
//        mainBinding.av.startTime = 1000
//        mainBinding.av.startTime = 2000
//        mainBinding.av.startTime = 3000
//        mainBinding.av.startTime = 4000
        mainBinding.av.path = DataSource.mp3_2
        mainBinding.av.speeds = mutableListOf(0.8f, 1.0f, 1.1f, 1.2f, 1.5f)
        mainBinding.av.speedLevel = 1
        mainBinding.av.startTime = 20000
        mainBinding.av1.path = DataSource.mp3
        mainBinding.av2.path = DataSource.mp3
        mainBinding.av3.path = DataSource.mp3
        mainBinding.calendar.setOnClickListener {
            startActivity(Intent(this@MainActivity, MainActivity2::class.java))
        }
        mainBinding.pdf.setOnClickListener {
            startActivity(Intent(this@MainActivity, MainActivity3::class.java))
        }

        mainBinding.bigImg.setOnClickListener {
            startActivity(Intent(this@MainActivity, MainActivity4::class.java))
        }
        mainBinding.tree.setOnClickListener {
            startActivity(Intent(this@MainActivity, MainActivity5::class.java))
        }


//        mainBinding.av.onPause()


//        mainBinding.word.isFocusableInTouchMode = true
//        mainBinding.word.isClickable = true
//        mainBinding.word.isLongClickable = true
//        mainBinding.word.movementMethod = WordMovementMethod()
//        mainBinding.word.setText(DataSource.html, BufferType.SPANNABLE)

//        lifecycleScope.launchWhenResumed {
//            loading.show()
//            delay(3000)
//            loading.dismiss()
//        }

//        val anmi = Rotate3DAnimation(
//            100f.dp2px(),
//            100f.dp2px()
//        )
//        anmi.fillAfter = true
//        mainBinding.btn.startAnimation(anmi)

//        ObjectAnimator.ofFloat(mainBinding.tv, View.ROTATION_X, 0f, 180f).apply{
//            duration = 3000
//            startDelay = 2000
//            start()
//        }

//        val animX = ObjectAnimator.ofFloat(mainBinding.tv, "x", 50f)
//        val animY = ObjectAnimator.ofFloat(mainBinding.tv, "y", 100f)
//        AnimatorSet().apply {
//            playTogether(animX, animY)
//            startDelay = 2000
//            start()
//        }
//        mainBinding.tv.animate()
//            .setDuration(2000)
//            .setStartDelay(1000)
//            .rotationX(50f)
//            .rotationY(100f)
    }

    override fun onDestroy() {
        super.onDestroy()
        mainBinding.av.release()
        mainBinding.av1.release()
        mainBinding.av2.release()
        mainBinding.av3.release()

    }
}